#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
    void swap(char &a,char &b)
    {
        char temp = a;
        a = b;
        b = temp;
    }
    vector<string> Permutation(string str) {
        vector<string> v;
    	permutationCore(v,str,0);
    	sort(v.begin(),v.end());
        return v;
    }

    void permutationCore(vector<string> &v,string str,int start)
    {
    	if(start == str.size() - 1)
    	{
            v.push_back(str);
            return;
    	}
    	for(int i = start ; i < str.size() ; ++i)
    	{
            if(str[i] == str[start])
                continue;
            swap(str[i],str[start]);
    		permutationCore(v,str,start+1);
            swap(str[i],str[start]);
    	}
    }

    void printVector(vector<string> v)
    {
    	int cnt = 0;
    	for(auto bg = v.begin() ; bg != v.end(); ++bg)
		{
			cout<<*bg<<',';
			++cnt;
		}
		cout<<cnt<<endl;
    }
};

int main()
{

	Solution s;
	int cnt = 0;
	vector<string> v = s.Permutation(string("abcdee"));
	cout<<"result:"<<endl;
	s.printVector(v);
	return 0;
}